<template>
  <div class="login-container">
    <div class="login-box">
      <h1 class="login-title">登录</h1>
      <el-form :model="loginForm" ref="loginFormRef" label-width="80px">
        <el-form-item label="用户名">
          <el-input v-model="loginForm.username" placeholder="请输入用户名" />
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="loginForm.password" type="password" placeholder="请输入密码" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" class="login-button" @click="handleLogin">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';

const router = useRouter();
const loginFormRef = ref(null);
const loginForm = ref({
  username: '',
  password: ''
});

const handleLogin = () => {
  // 这里简单模拟登录成功，实际应用中需要与后端交互验证
  localStorage.setItem('isLoggedIn', 'true');
  router.push('/');
};
</script>

<style scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: #304156; /* 与项目头部背景颜色统一 */
}

.login-box {
  background-color: #fff;
  padding: 40px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  width: 360px;
}

.login-title {
  text-align: center;
  margin-bottom: 30px;
  color: #304156;
  font-size: 24px;
  font-weight: bold;
}

.login-button {
  width: 100%;
}
</style>